
#include "connection.h"
#include "../../NLogic/Static.h"
#include "../../Proxy.h"

namespace ProjectZ { namespace NCommand { namespace NConnection {

void CS_REQ_LOGOUT::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	// 1. Channel 변경 시
	// 2. MainFriendList 로 상태 변경시
	PREPARE_PACKET;

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	pAck->MakePacket(CMD_SC_REQ_LOGOUT);
	pUser->Send(pAck);

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_REQ_LOGOUT NULL == pSpace");
		return;
	}

//	ServerLocation svrLoc;
//	svrLoc.server_id = ::ProjectZ::Config::Instance().GetResourceDatabase()._channelUniqueIndex;
//	svrLoc.channel_id = 0;
//
//	::ProjectZ::NLogic::Memcached * clsMemcached = ::ProjectZ::NLogic::Static::Instance().GETMEMCACHED();
//	clsMemcached->Set(std::to_string(pUser->GetUserSeq()).c_str(), reinterpret_cast<char*>(&svrLoc), sizeof(ServerLocation), 0);

	pSpace->LeaveUser(pUser);
	pUser->FlushUserInfo();
	pUser->FlushCharacterInfo();

	pUser->SetSpace(NULL);

	pUser->CacheBagInfo(false);
}


} /*NConnection*/ } /*NCommand*/ } /*ProjectZ*/


